<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>主页</title>
        <link rel="stylesheet" href="css/bootstrap.min.css">
        <script src="js/jquery-3.4.1.min.js"></script>
        <script src="js/bootstrap.bundle.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
        <script>
            $(document).ready(function () {
                // 使用AJAX获取用户信息
                $.ajax({
                    url: '/day08-auto-login/user/getUser', // 服务器端获取用户信息的接口的URL，需要根据实际情况修改
                    type: 'GET',
                    success: function (response) {
                        // 这里的response是服务器返回的数据
                        if (response.code = 100) {
                            // 如果用户已登录，显示用户名和注销链接
                            $('#user-nav').html(`
                              <li class="nav-item">
                                <a class="nav-link" href="#">${response.data.username}</a>
                              </li>
                              <span class="text-white align-self-center">|</span>
                              <li class="nav-item">
                                <a class="nav-link" href="#" id="logout">注销</a>
                              </li>
                            `);
                            // 添加注销链接的点击事件
                            $('#logout').click(function (e) {
                                e.preventDefault();
                                $.ajax({
                                    url: '/day08-auto-login/user/logout',
                                    type: 'POST',
                                    success: function (response) {
                                        // 如果成功注销，显示注册和登录链接
                                        if (response.code == 102) {
                                            $('#user-nav').html(`
                                              <li class="nav-item">
                                                <a class="nav-link" href="#">注册</a>
                                              </li>
                                              <span class="text-white align-self-center">|</span>
                                              <li class="nav-item">
                                                <a class="nav-link" href="/day08-auto-login/login.html">登录</a>
                                              </li>
                                         `);
                                        }
                                    }
                                });
                            });
                        } else if (response.code = 102) {
                            // 如果用户未登录，显示注册和登录链接
                            $('#user-nav').html(`
                                  <li class="nav-item">
                                    <a class="nav-link" href="#">注册</a>
                                  </li>
                                  <span class="text-white align-self-center">|</span>
                                  <li class="nav-item">
                                    <a class="nav-link" href="/day08-auto-login/login.html">登录</a>
                                  </li>
                             `);
                        }
                    }
                });
            });
        </script>
    </head>
    <body>
        <!--使整个页面居中-->
        <div class="container">
            <!--导航栏-->
            <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
                        aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav">
                        <li class="nav-item active">
                            <a class="nav-link" href="#">主页 <span class="sr-only">(current)</span></a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">手机</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">平板</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">电脑</a>
                        </li>
                    </ul>
                    <ul class="navbar-nav offset-md-8" id="user-nav">
                        <li class="nav-item">
                            <a class="nav-link" href="#">注册</a>
                        </li>
                        <span class="text-white align-self-center">|</span>
                        <li class="nav-item">
                            <a class="nav-link" href="/day08-auto-login/login.html">登录</a>
                        </li>
                    </ul>
                </div>
            </nav>
            <!-- 其他页面内容... -->
            <br/>
            <!--轮播图-->
            <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
                <ol class="carousel-indicators">
                    <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
                    <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
                    <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
                </ol>
                <div class="carousel-inner">
                    <div class="carousel-item active">
                        <img src="img/1.png" class="d-block w-100" width="300px" height="350px" alt="...">
                    </div>
                    <div class="carousel-item">
                        <img src="img/2.jpg" class="d-block w-100" width="300px" height="350px" alt="...">
                    </div>
                    <div class="carousel-item">
                        <img src="img/3.jpg" class="d-block w-100" width="300px" height="350px" alt="...">
                    </div>
                </div>
                <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
                    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                    <span class="sr-only">Previous</span>
                </a>
                <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
                    <span class="carousel-control-next-icon" aria-hidden="true"></span>
                    <span class="sr-only">Next</span>
                </a>
            </div>
            <br/>
            <!--内容页-->
            <div class="row">
                <div class="col-md-3">
                    <div class="row">
                        <div class="col-md-3"><img src="img/hjh_01.gif"></div>
                        <div class="col-md-3"><img src="img/hjh_02.gif"></div>
                        <div class="col-md-3"><img src="img/hjh_03.gif"></div>
                        <div class="w-100"></div>
                        <div class="col-md-3"><img src="img/hjh_06.gif"></div>
                        <div class="col-md-3"><img src="img/hjh_05.gif"></div>
                        <div class="col-md-3"><img src="img/hjh_06.gif"></div>
                    </div>
                </div>
                <div class="col-md-3"><img src="img/pinghengche.jpg" width="260px" height="160px"></div>
                <div class="col-md-3"><img src="img/pinghengche.jpg" width="260px" height="160px"></div>
                <div class="col-md-3"><img src="img/pinghengche.jpg" width="260px" height="160px"></div>
            </div>
            <br/>
            <!--明星单品内容-->
            <div class="row">
                <div class="col-md-12"><h3>明星单品</h3></div>
            </div>
            <div class="row">
                <div class="col-md-2">
                    <img src="img/pinpai1.png" width="160px" height="160px"><br/>
                    <a href="">MAX</a><br/>
                    5月9日-21日享花呗12期分期免息<br/>
                    <span class="text-danger">3499元起</span>
                </div>
                <div class="col-md-2" style="margin-left:50px">
                    <img src="img/pinpai2.png" width="160px" height="160px"><br/>
                    <a href="">SuperMin</a><br/>
                    5月9日-21日享花呗12期分期免息<br/>
                    <span class="text-danger">3499元起</span>
                </div>
                <div class="col-md-2" style="margin-left:50px">
                    <img src="img/pinpai3.png" width="160px" height="160px"><br/>
                    <a href="">SuperMan</a><br/>
                    5月9日-21日享花呗12期分期免息<br/>
                    <span class="text-danger">3499元起</span>
                </div>
                <div class="col-md-2" style="margin-left:50px">
                    <img src="img/pinpai4.png" width="160px" height="160px"><br/>
                    <a href="">超薄液晶4K电视</a><br/>
                    5月9日-21日享花呗12期分期免息<br/>
                    <span class="text-danger">3499元起</span>
                </div>
                <div class="col-md-2" style="margin-left:40px">
                    <img src="img/pinpai5.png" width="160px" height="160px"><br/>
                    <a href="">超薄窄边框笔记本</a><br/>
                    5月9日-21日享花呗12期分期免息<br/>
                    <span class="text-danger">3499元起</span>
                </div>
            </div>
            <br/>
            <!--配件内容-->
            <div class="row">
                <div class="col-md-12"><h3>配件</h3></div>
            </div>
            <div class="row">
                <div class="col-md-4"><img src="img/discount.png"></div>
                <div class="col-md-2"><img src="img/peijian2.jpg"></div>
                <div class="col-md-2"><img src="img/peijian5.jpg"></div>
                <div class="col-md-2"><img src="img/peijian2.jpg"></div>
                <div class="col-md-2"><img src="img/peijian5.jpg"></div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <img src="img/12.12.jpg" width="294px" height="373px">
                </div>
                <div class="col-md-2">
                    <img src="img/peijian2.jpg">
                </div>
                <div class="col-md-2">
                    <img src="img/peijian5.jpg">
                </div>
                <div class="col-md-2">
                    <img src="img/peijian8.jpg">
                </div>
                <div class="col-md-2">
                    <div class="row">
                        <div class="col-md-12"><img src="img/peijian8.jpg"></div>
                        <div class="col-md-12"><img src="img/liulangengduo.png"></div>
                    </div>
                </div>
            </div>
            <br/>
            <!--页脚-->
            <div class="row">
                <div class="col-md-12 text-center">
                    <a href="#">关于我们</a>
                    <a href="#">联系我们</a>
                    <a href="#">联系客服</a>
                    <a href="#">关于我们</a>
                    <a href="#">关于我们</a>
                    <a href="#">关于我们</a>
                </div>
                <div class="col-md-12 text-center">
                    Copyright © 2004 - 2020 云智互联 版权所有
                </div>
            </div>
        </div>
    </body>
</html>